package ar.edu.itba.it.raytracer.scene

import scala.math.{ pow, min }
import ar.edu.itba.it.raytracer.engine.{ Ray, Vector, Color }
import scala.math.sqrt

case class Plane(point: Vector, direction: Vector) extends Geom {
  import Geom.eps
  def normal(point: Vector, ray: Ray): Vector = if (direction * ray.direction > 0) direction * -1 else direction

  def intersect(ray: Ray): Option[Vector] = {
    var result: Option[Vector] = None
    val denom = ray.direction * direction
    if (denom != 0) {
      val t = ((point - ray.origin) * direction) / denom
      if (t > eps) result = Some(ray(t))
    }
    result
  }
}